#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    connect(ui->pushButton_2,&QPushButton::clicked,this,&Widget::Up);
    connect(ui->pushButton_3,&QPushButton::clicked,this,&Widget::Left);
    connect(ui->pushButton_4,&QPushButton::clicked,this,&Widget::Right);
    connect(ui->pushButton_5,&QPushButton::clicked,this,&Widget::Down);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::Up()
{
    // 这只是一个局部变量，还要添加到target上。
    QRect rect = ui->pushButton_target->geometry();

    // rect.setY(rect.y() - 5);

    // ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x(),rect.y() - 5,rect.width(),rect.height());

    on_PushButter_Clicked();
}

void Widget::Down()
{
    QRect rect = ui->pushButton_target->geometry();

    // rect.setY(rect.y() + 5);

    // ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x(),rect.y() + 5,rect.width(),rect.height());

    on_PushButter_Clicked();
}

void Widget::Left()
{
    QRect rect = ui->pushButton_target->geometry();

    // rect.setX(rect.x() + 5);

    // ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x() - 5,rect.y(),rect.width(),rect.height());

    on_PushButter_Clicked();
}

void Widget::Right()
{
    QRect rect = ui->pushButton_target->geometry();

    // rect.setX(rect.x() - 5);

    // ui->pushButton_target->setGeometry(rect);

    ui->pushButton_target->setGeometry(rect.x() + 5,rect.y(),rect.width(),rect.height());

    on_PushButter_Clicked();
}


void Widget::on_PushButter_Clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    qDebug() << rect;
}
